package cn.gson.springboot.model.pojos;

import javax.persistence.*;
import java.math.BigDecimal;
import java.sql.Date;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "contract_", schema = "crm")
public class Contract {
    private int contractId;//订单合同id
    private String contractTheme;//主题
    private BigDecimal contractTotalAmount;//总金额
    private BigDecimal contractBackAmount;//回款金额
    private Integer contractStatus;//执行状态
    private String contractEmpName;//所有者
    private Integer contractSort;//分类
    private Date contractStartTime;//下单时间
    private Date contractEndTime;//结束时间
    private String contractCustomerSigner;//客户签约人
    private String contractOurSigner;//我方签约人
    private Integer contractPaymentMethods;//付款方式
    private Integer contractMoneyMethods;//结款方式
    private String contractBodyText;//正文及附件
    private String contractNo;//合同订单号
    private BigDecimal contractInvoiceAmount;//发票金额
    private String contractProductService;//产品服务
    private String contractChance;//对应机会
    private String contractNote;//备注
    private Integer contractTimes;//判断合同期
    private Collection<Collectionrecord> collectionrecordsByContractId;//回款记录
    private Employee employeeByEmpId;//员工
    private Customer customerByCustomerId;//客户
    private Collection<Invoice> invoicesByContractId;//发货表
    private Collection<InvoiceRecord> invoicerecordsByContractId;//开票记录表
    private Collection<Outbound> outboundsByContractId;//出库表
    private Collection<Planreceivable> planreceivablesByContractId;//计划回款
    private Collection<ProductDetail> productDetailsByContractId;//产品明细表
    private Collection<Return> returnsByContractId;//退货单
    private Opportunity opportunityByOppId;//销售机会

    private Integer contractAppStatus;//审批状态
    private List<Approval> approvalsByContractId;
    private List<ApprovalRecord> approvalRecordsByContractId;
    private Employee employeeByAppEmpId;// 审批人

    @Id
    @Column(name = "contract_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY,generator = "seq")
    public int getContractId() {
        return contractId;
    }

    public void setContractId(int contractId) {
        this.contractId = contractId;
    }


    @Basic
    @Column(name = "contract_theme", nullable = true, length = 255)
    public String getContractTheme() {
        return contractTheme;
    }

    public void setContractTheme(String contractTheme) {
        this.contractTheme = contractTheme;
    }

    @Basic
    @Column(name = "contract_total_amount", nullable = true, precision = 2)
    public BigDecimal getContractTotalAmount() {
        return contractTotalAmount;
    }

    public void setContractTotalAmount(BigDecimal contractTotalAmount) {
        this.contractTotalAmount = contractTotalAmount;
    }

    @Basic
    @Column(name = "contract_back_amount", nullable = true, precision = 2)
    public BigDecimal getContractBackAmount() {
        return contractBackAmount;
    }

    public void setContractBackAmount(BigDecimal contractBackAmount) {
        this.contractBackAmount = contractBackAmount;
    }

    @Basic
    @Column(name = "contract_status", nullable = true)
    public Integer getContractStatus() {
        return contractStatus;
    }

    public void setContractStatus(Integer contractStatus) {
        this.contractStatus = contractStatus;
    }

    @Basic
    @Column(name = "contract_emp_name", nullable = true, length = 255)
    public String getContractEmpName() {
        return contractEmpName;
    }

    public void setContractEmpName(String contractEmpName) {
        this.contractEmpName = contractEmpName;
    }

    @Basic
    @Column(name = "contract_sort", nullable = true)
    public Integer getContractSort() {
        return contractSort;
    }

    public void setContractSort(Integer contractSort) {
        this.contractSort = contractSort;
    }

    @Basic
    @Column(name = "contract_start_time", nullable = true)
    public Date getContractStartTime() {
        return contractStartTime;
    }

    public void setContractStartTime(Date contractStartTime) {
        this.contractStartTime = contractStartTime;
    }

    @Basic
    @Column(name = "contract_end_time", nullable = true)
    public Date getContractEndTime() {
        return contractEndTime;
    }

    public void setContractEndTime(Date contractEndTime) {
        this.contractEndTime = contractEndTime;
    }

    @Basic
    @Column(name = "contract_customer_signer", nullable = true, length = 255)
    public String getContractCustomerSigner() {
        return contractCustomerSigner;
    }

    public void setContractCustomerSigner(String contractCustomerSigner) {
        this.contractCustomerSigner = contractCustomerSigner;
    }

    @Basic
    @Column(name = "contract_our_signer", nullable = true, length = 255)
    public String getContractOurSigner() {
        return contractOurSigner;
    }

    public void setContractOurSigner(String contractOurSigner) {
        this.contractOurSigner = contractOurSigner;
    }

    @Basic
    @Column(name = "contract_payment_methods", nullable = true)
    public Integer getContractPaymentMethods() {
        return contractPaymentMethods;
    }

    public void setContractPaymentMethods(Integer contractPaymentMethods) {
        this.contractPaymentMethods = contractPaymentMethods;
    }

    @Basic
    @Column(name = "contract_money_methods", nullable = true)
    public Integer getContractMoneyMethods() {
        return contractMoneyMethods;
    }

    public void setContractMoneyMethods(Integer contractMoneyMethods) {
        this.contractMoneyMethods = contractMoneyMethods;
    }

    @Basic
    @Column(name = "contract_body_text", nullable = true, length = 255)
    public String getContractBodyText() {
        return contractBodyText;
    }

    public void setContractBodyText(String contractBodyText) {
        this.contractBodyText = contractBodyText;
    }

    @Basic
    @Column(name = "contract_no", nullable = true, length = 255)
    public String getContractNo() {
        return contractNo;
    }

    public void setContractNo(String contractNo) {
        this.contractNo = contractNo;
    }

    @Basic
    @Column(name = "contract_invoice_amount", nullable = true, precision = 2)
    public BigDecimal getContractInvoiceAmount() {
        return contractInvoiceAmount;
    }

    public void setContractInvoiceAmount(BigDecimal contractInvoiceAmount) {
        this.contractInvoiceAmount = contractInvoiceAmount;
    }

    @Basic
    @Column(name = "contract_product_service", nullable = true, length = 255)
    public String getContractProductService() {
        return contractProductService;
    }

    public void setContractProductService(String contractProductService) {
        this.contractProductService = contractProductService;
    }

    @Basic
    @Column(name = "contract_chance", nullable = true, length = 255)
    public String getContractChance() {
        return contractChance;
    }

    public void setContractChance(String contractChance) {
        this.contractChance = contractChance;
    }

    @Basic
    @Column(name = "contract_note", nullable = true, length = 255)
    public String getContractNote() {
        return contractNote;
    }

    public void setContractNote(String contractNote) {
        this.contractNote = contractNote;
    }

    @Basic
    @Column(name = "contract_app_status", nullable = true, length = 255)
    public Integer getContractAppStatus() {
        return contractAppStatus;
    }

    public void setContractAppStatus(Integer contractAppStatus) {
        this.contractAppStatus = contractAppStatus;
    }

    @Basic
    @Column(name = "contract_times", nullable = true, length = 255)
    public Integer getContractTimes() {
        return contractTimes;
    }

    public void setContractTimes(Integer contractTimes) {
        this.contractTimes = contractTimes;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Contract contract = (Contract) o;
        return contractId == contract.contractId &&
                Objects.equals(contractTheme, contract.contractTheme) &&
                Objects.equals(contractTotalAmount, contract.contractTotalAmount) &&
                Objects.equals(contractBackAmount, contract.contractBackAmount) &&
                Objects.equals(contractStatus, contract.contractStatus) &&
                Objects.equals(contractEmpName, contract.contractEmpName) &&
                Objects.equals(contractSort, contract.contractSort) &&
                Objects.equals(contractStartTime, contract.contractStartTime) &&
                Objects.equals(contractEndTime, contract.contractEndTime) &&
                Objects.equals(contractCustomerSigner, contract.contractCustomerSigner) &&
                Objects.equals(contractOurSigner, contract.contractOurSigner) &&
                Objects.equals(contractPaymentMethods, contract.contractPaymentMethods) &&
                Objects.equals(contractMoneyMethods, contract.contractMoneyMethods) &&
                Objects.equals(contractBodyText, contract.contractBodyText) &&
                Objects.equals(contractNo, contract.contractNo) &&
                Objects.equals(contractInvoiceAmount, contract.contractInvoiceAmount) &&
                Objects.equals(contractProductService, contract.contractProductService) &&
                Objects.equals(contractChance, contract.contractChance) &&
                Objects.equals(contractTimes, contract.contractTimes) &&
                Objects.equals(contractNote, contract.contractNote);
    }

    @Override
    public int hashCode() {
        return Objects.hash(contractId, contractTheme, contractTotalAmount, contractTimes,contractBackAmount, contractStatus, contractEmpName, contractSort, contractStartTime, contractEndTime, contractCustomerSigner, contractOurSigner, contractPaymentMethods, contractMoneyMethods, contractBodyText, contractNo, contractInvoiceAmount, contractProductService, contractChance, contractNote);
    }

    @OneToMany(mappedBy = "contractByContractId")
    public Collection<Collectionrecord> getCollectionrecordsByContractId() {
        return collectionrecordsByContractId;
    }

    public void setCollectionrecordsByContractId(Collection<Collectionrecord> collectionrecordsByContractId) {
        this.collectionrecordsByContractId = collectionrecordsByContractId;
    }

    @ManyToOne
    @JoinColumn(name = "emp_id", referencedColumnName = "emp_id")
    public Employee getEmployeeByEmpId() {
        return employeeByEmpId;
    }

    public void setEmployeeByEmpId(Employee employeeByEmpId) {
        this.employeeByEmpId = employeeByEmpId;
    }

    @ManyToOne
    @JoinColumn(name = "customer_id", referencedColumnName = "customer_id")
    public Customer getCustomerByCustomerId() {
        return customerByCustomerId;
    }

    public void setCustomerByCustomerId(Customer customerByCustomerId) {
        this.customerByCustomerId = customerByCustomerId;
    }

    @OneToMany(mappedBy = "contractByContractId")
    public Collection<Invoice> getInvoicesByContractId() {
        return invoicesByContractId;
    }

    public void setInvoicesByContractId(Collection<Invoice> invoicesByContractId) {
        this.invoicesByContractId = invoicesByContractId;
    }

    @OneToMany(mappedBy = "contractByContractId")
    public Collection<InvoiceRecord> getInvoicerecordsByContractId() {
        return invoicerecordsByContractId;
    }

    public void setInvoicerecordsByContractId(Collection<InvoiceRecord> invoicerecordsByContractId) {
        this.invoicerecordsByContractId = invoicerecordsByContractId;
    }

    @OneToMany(mappedBy = "contractByContractId")
    public Collection<Outbound> getOutboundsByContractId() {
        return outboundsByContractId;
    }

    public void setOutboundsByContractId(Collection<Outbound> outboundsByContractId) {
        this.outboundsByContractId = outboundsByContractId;
    }

    @OneToMany(mappedBy = "contractByContractId")
    public Collection<Planreceivable> getPlanreceivablesByContractId() {
        return planreceivablesByContractId;
    }

    public void setPlanreceivablesByContractId(Collection<Planreceivable> planreceivablesByContractId) {
        this.planreceivablesByContractId = planreceivablesByContractId;
    }

    @OneToMany(mappedBy = "contractByContractId")
    public Collection<ProductDetail> getProductDetailsByContractId() {
        return productDetailsByContractId;
    }

    public void setProductDetailsByContractId(Collection<ProductDetail> productDetailsByContractId) {
        this.productDetailsByContractId = productDetailsByContractId;
    }

    @OneToMany(mappedBy = "contractByContractId")
    public Collection<Return> getReturnsByContractId() {
        return returnsByContractId;
    }

    public void setReturnsByContractId(Collection<Return> returnsByContractId) {
        this.returnsByContractId = returnsByContractId;
    }

    @ManyToOne
    @JoinColumn(name = "opp_id", referencedColumnName = "opp_id")
    public Opportunity getOpportunityByOppId() {
        return opportunityByOppId;
    }

    public void setOpportunityByOppId(Opportunity opportunityByOppId) {
        this.opportunityByOppId = opportunityByOppId;
    }

    @OneToMany(mappedBy = "contractByContractId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<Approval> getApprovalsByContractId() {
        return approvalsByContractId;
    }

    public void setApprovalsByContractId(List<Approval> approvalsByContractId) {
        this.approvalsByContractId = approvalsByContractId;
    }

    @OneToMany(mappedBy = "contractByContractId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<ApprovalRecord> getApprovalRecordsByContractId() {
        return approvalRecordsByContractId;
    }

    public void setApprovalRecordsByContractId(List<ApprovalRecord> approvalRecordsByContractId) {
        this.approvalRecordsByContractId = approvalRecordsByContractId;
    }

    @ManyToOne
    @JoinColumn(name = "app_emp_id", referencedColumnName = "emp_id")
    public Employee getEmployeeByAppEmpId() {
        return employeeByAppEmpId;
    }

    public void setEmployeeByAppEmpId(Employee employeeByAppEmpId) {
        this.employeeByAppEmpId = employeeByAppEmpId;
    }
}
